<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 18-12-14
 * Time: 下午4:56
 */

namespace workin\modules\others\controllers;


use common\models\AliCarinfoGetLog;
use common\components\tools\Tools;
use yii\httpclient\Exception;
use yii\web\Controller;

class InvoiceController extends Controller
{
    public function actionCarShow($ali_carinfo_get_log_id)
    {
        $model = AliCarinfoGetLog::findOne(['id' => $ali_carinfo_get_log_id, 'type' => AliCarinfoGetLog::TYPE_LSFPZW]);
        if (!$model){
            throw new Exception("没有找到模型", 201812171000);
        }
        $invoiceName = $model->invoiceName;
        $data['daxie'] = Tools::num_to_rmb($model->jshe);
        if(strpos($invoiceName,'机动车销售统一发票') !== false){
            $model->resp_body = json_decode($model->resp_body);
            $model->resp_body->invoiceResult = json_decode($model->resp_body->invoiceResult);
            $data['suiwu'] = preg_replace("|[0-9a-zA-Z/]+|",'', $model->resp_body->invoiceResult->taxOfficeName);
            $data['suiwucode'] = preg_replace('/([\x80-\xff]*)/i','',$model->resp_body->invoiceResult->taxOfficeName);
            return $this->renderPartial('new-car-show', ['model' => $model,'data'=>$data]);
        }
        if(strpos($invoiceName,'二手车销售统一发票') !== false){
            $model->resp_body = json_decode($model->resp_body);
            $model->resp_body->invoiceResult = json_decode($model->resp_body->invoiceResult);
            return $this->renderPartial('used-car-show', ['model' => $model,'data'=>$data]);
        }
    }
}